home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / WASTE 1.2 / WASTE Demo ƒ / WEDemoInit.c < prev    next >
Text File  |  1996-06-17  |  4KB  |  181 lines

  1. /*
  2.     WASTE Demo Project:
  3.     Initialization and Finalization Routines
  4.  
  5.     Copyright © 1993-1996 Marco Piovanelli
  6.     All Rights Reserved
  7.  
  8.     C port by John C. Daub
  9. */
  10.  
  11.  
  12. #ifndef __DIALOGS__
  13. #include <Dialogs.h>
  14. #endif
  15.  
  16. #ifndef __FONTS__
  17. #include <Fonts.h>
  18. #endif
  19.  
  20. #ifndef __GESTALT__
  21. #include <Gestalt.h>
  22. #endif
  23.  
  24. #ifndef __SCRAP__
  25. #include <Scrap.h>
  26. #endif
  27.  
  28. #ifndef __TEXTSERVICES__
  29. #include <TextServices.h>
  30. #endif
  31.  
  32. #ifndef __WEDEMOAPP__
  33. #include "WEDemoIntf.h"
  34. #endif
  35.  
  36. #include "WEObjectHandlers.h"
  37.  
  38. OSErr Initialize( void )
  39. {
  40.     long            response;
  41.     short            i;
  42.     OSErr            err;
  43.  
  44.     // expand the zone to its maximum size
  45.  
  46.     MaxApplZone( );
  47.  
  48.     // allocate some extra master pointer blocks
  49.  
  50.     for ( i = 0; i < 6; i++ )
  51.     {
  52.         MoreMasters( );
  53.     }
  54.  
  55.     // initialize the Toolbox
  56.  
  57.     InitGraf( &qd.thePort );
  58.     InitFonts( );
  59.     InitWindows( );
  60.     InitMenus( );
  61.     TEInit( );    // tho we use WASTE for text stuff, dialogs, etc all use TextEdit so don't remove this!
  62.     InitDialogs( nil );
  63.     InitCursor( );
  64.     FlushEvents( everyEvent, 0 );
  65.  
  66.     // if desk scrap is too large, unload it
  67.  
  68.     if ( InfoScrap( )->scrapSize > kScrapThreshold )
  69.     {
  70.         UnloadScrap( );
  71.     }
  72.  
  73.     // make sure system software versino is 7.0 or newer (classic 68K only)
  74.  
  75.     #if !GENERATINGCFM
  76.     if ( ( Gestalt( gestaltSystemVersion, &response ) != noErr ) || ( response < kMinSystemVersion ) )
  77.     {
  78.         SetCursor( &qd.arrow );
  79.         response = Alert( kAlertNeedSys7, nil );
  80.         return -1;
  81.     }
  82.     #endif
  83.  
  84.     // determine whether color Quickdraw is available
  85.  
  86.     gHasColorQD = (Gestalt(gestaltQuickdrawVersion, &response) == noErr)
  87.                     && (response >= gestalt8BitQD);
  88.  
  89.     // determine whether the Drag Manager is available
  90.  
  91.     gHasDragAndDrop = (Gestalt( gestaltDragMgrAttr, &response ) == noErr )
  92.                     && BTST( response, gestaltDragMgrPresent );
  93.  
  94. #if GENERATINGCFM
  95.     // additional check needed if DragLib is weak-linked
  96.     gHasDragAndDrop = gHasDragAndDrop && (&NewDrag != nil);
  97. #endif
  98.  
  99.     // determine whether the Text Services Manager is available
  100.  
  101.     gHasTextServices = ( Gestalt( gestaltTSMgrVersion, &response ) == noErr );
  102.  
  103.     // register this application with the TSM
  104.  
  105.     if ( gHasTextServices )
  106.     {
  107.         if ( ( err = InitTSMAwareApplication( ) ) != noErr )
  108.             goto cleanup;
  109.     }
  110.  
  111.     // install default drag handlers
  112.  
  113.     if ( gHasDragAndDrop )
  114.     {
  115.         if ( ( err = InstallDragHandlers( ) ) != noErr )
  116.             goto cleanup;
  117.     }
  118.  
  119.     // install the sample object handlers for pictures and sounds
  120.  
  121.     if ((err = WEInstallObjectHandler(kTypePicture, weNewHandler,
  122.                 (UniversalProcPtr) NewWENewObjectProc(HandleNewPicture), nil)) != noErr)
  123.         goto cleanup;
  124.  
  125.     if ((err = WEInstallObjectHandler(kTypePicture, weDisposeHandler,
  126.                 (UniversalProcPtr) NewWEDisposeObjectProc(HandleDisposePicture), nil)) != noErr)
  127.         goto cleanup;
  128.  
  129.     if ((err = WEInstallObjectHandler(kTypePicture, weDrawHandler,
  130.                 (UniversalProcPtr) NewWEDrawObjectProc(HandleDrawPicture), nil)) != noErr)
  131.         goto cleanup;
  132.  
  133.     if ((err = WEInstallObjectHandler(kTypeSound, weNewHandler,
  134.                 (UniversalProcPtr) NewWENewObjectProc(HandleNewSound), nil)) != noErr)
  135.         goto cleanup;
  136.  
  137.     if ((err = WEInstallObjectHandler(kTypeSound, weDrawHandler,
  138.                 (UniversalProcPtr) NewWEDrawObjectProc(HandleDrawSound), nil)) != noErr)
  139.         goto cleanup;
  140.  
  141.     if ((err = WEInstallObjectHandler(kTypeSound, weClickHandler,
  142.                 (UniversalProcPtr) NewWEClickObjectProc(HandleClickSound), nil)) != noErr)
  143.         goto cleanup;
  144.  
  145.     // perform other initialization chores
  146.  
  147.     if ( ( err = InitializeEvents( ) ) != noErr )
  148.         goto cleanup;
  149.  
  150.     if ( ( err = InitializeMenus( ) ) != noErr )
  151.         goto cleanup;
  152.  
  153.     // clear result code
  154.     err = noErr;
  155.  
  156. cleanup:
  157.     if ( err != noErr )
  158.     {
  159.         ErrorAlert( err );
  160.     }
  161.  
  162.     return err;
  163. }
  164.  
  165. void Finalize( void )
  166. {
  167.     // remove drag handlers
  168.  
  169.     if ( gHasDragAndDrop )
  170.     {
  171.         RemoveDragHandlers( );
  172.     }
  173.  
  174.     // notify text services that we're closing down
  175.  
  176.     if ( gHasTextServices )
  177.     {
  178.         CloseTSMAwareApplication( );
  179.     }
  180. }
  181.